#include "gtest/gtest.h"

#include "recovery/log/FileLog.h"
#include "recovery/Block.h"

using namespace recovery;
using namespace log;


TEST(LogTest, testMain){
    const char * dir = ".";
    const char * name = "log.data";

    std::unique_ptr<ILog> log( new FileLog(name, dir));
    {
        ASSERT_EQ(0, log->open());
        const std::string data("data buffer");
        ASSERT_EQ(data.size(), (size_t)(log->append(data)));
        ASSERT_EQ(0, log->sync());

        {
            recovery::Block block;
            int ret = log->positionedRead(0, block.addr(), block.bytes());
            ASSERT_EQ(data.size(), (size_t)ret);
        }

        {
            recovery::Block blocks(10);
            int ret = log->positionedRead(1, blocks.addr(), blocks.bytes());
            ASSERT_EQ(data.size() - 1,  (size_t)ret);
        }

        ASSERT_EQ(0, log->close());
        ASSERT_EQ(0, log->remove());
    }
}
